<script>
    function toggle(obj, width, height, message = '') {
        var url = obj.attr('url');
        var jump_url = obj.attr('jump_url');

        //自定页
        parent.layer.open({
            type: 2,
            title: message,
            skin: 'layui-layer-rim', //加上边框
            area: [width, height], //宽高
            content: [url, 'yes'],
            end: function () {
                if(typeof(jump_url) == 'undefined'){
                    window.location.reload();
                }else{
                    window.location.href=jump_url;
                }

            }
        });
    }

    function toggle_info(obj, width, height, message = '') {
        var url = obj.attr('url');
        var jump_url = obj.attr('jump_url');

        //自定页
        parent.layer.open({
            type: 2,
            title: message,
            skin: 'layui-layer-rim', //加上边框
            area: [width, height], //宽高
            content: [url, 'yes'],
            end: function () {
                $(".btn-groups").find('.active').click();

            }
        });
    }

    function del(obj){
        var url = obj.attr('url');
        var title =  "您确定要刪除?";
        var botton =  "刪除";
        var result =  "刪除成功";

        swal({
            title: title,
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: botton,
            closeOnConfirm: false
        }, function () {
            $.ajax({
                type: "post",
                url: url,
                dataType: "json",
                success: function(data) {

                    if(data.code == 200){
                        var swal_json = {
                            title : result,
                            type : "success"
                        }
                    }else if(data.code == 500){
                        var swal_json = {
                            title : data.message,
                            type : "error"
                        }
                    }


                    swal(swal_json,function(isConfirm){
                        window.location.reload();
                    });

                }
            });

        });
    }

    function do_edit(obj, title, botton, result, result_two){
        var url = obj.attr('url');
        var is_top = obj.attr('is_top');
        var title;
        var botton;
        var result;

        if(is_top != '1'){
            title =  "您确定要推荐职位";
            botton =  "操作";
            result =  "操作成功";
            result_two =  "您已经推荐了职位";
        }else{
            title =  "您确定要取消推荐职位";
            botton =  "取消推荐";
            result =  "取消推荐成功";
            result_two =  "您已经取消推荐了职位";
        }

        swal({
            title: title,
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: botton,
            closeOnConfirm: false
        }, function () {
            $.ajax({
                type: "post",
                url: url,
                dataType: "json",
                success: function(data) {

                    var swal_json = {
                        title : result,
                        text : result_two,
                        type : "success"
                    }

                    swal(swal_json,function(isConfirm){
                        window.location.reload();
                    });

                }
            });

        });
    }

    function do_reservation_edit(obj, title, result){
        var url = obj.attr('url');

        swal({
            title: title,
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "操作",
            closeOnConfirm: false
        }, function () {
            $.ajax({
                type: "post",
                url: url,
                dataType: "json",
                success: function(data) {
                    if(!data.status){
                        var swal_json = {
                            title: data.message,
                            type: "error"
                        }

                        swal(swal_json, function (isConfirm) {
                            //window.location.reload();
                        });
                    }else {
                        var swal_json = {
                            title: result,
                            type: "success"
                        }

                        swal(swal_json, function (isConfirm) {
                            window.location.reload();
                        });
                    }

                }
            });

        });
    }
</script>
